package indi.zhifa.recipe.bailan.busy.service.impl;

import com.querydsl.core.types.Predicate;
import indi.zhifa.recipe.bailan.busy.service.IOrmJpaService;
import indi.zhifa.recipe.bailan.busy.entity.po.OrmTestEntity;
import indi.zhifa.recipe.bailan.busy.dao.repository.OrmTestReposity;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
@Service
public class OrmJpaServiceImpl extends BaseOrmServiceImpl implements IOrmJpaService {

    private final OrmTestReposity mOrmTestReposity;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void initTestData() {
        List<OrmTestEntity> initOrmTestEntityList = getInitOrmTestEntityList("JPA");
        mOrmTestReposity.saveAll(initOrmTestEntityList);
    }

    @Override
    public Page<OrmTestEntity> page(Pageable pPageable, Predicate predicate) {
        Page<OrmTestEntity> ormTestEntityPage =  mOrmTestReposity.findAll(predicate,pPageable);
        return ormTestEntityPage;
    }
}
